<template>
	<z-container title="复核详情" :loading="state.loading">
		<view class="ss-p-x-32 ss-p-y-24 bg-white">
			<OrderMessage :info="info" />
			<uv-gap height="12"></uv-gap>
			<OrderInfoItem label="车牌号" :value="info.car_number" />
			<OrderInfoItem label="业务类型" :value="info.yewu_name" />
			<uv-gap height="12"></uv-gap>
			<z-required-title title="审核意见" />
			<uv-gap height="12"></uv-gap>
			<uv-textarea height="212rpx" placeholder="自动审核通过" disabled :modelValue="info.sh_remake"></uv-textarea>
			<uv-gap height="12"></uv-gap>
			<uv-line color="#eee"></uv-line>
			<z-required-title title="复核意见" />
			<uv-gap height="12"></uv-gap>
			<uv-textarea height="212rpx" placeholder="请输入复核意见" v-model="form.fh_remake"></uv-textarea>
			<uv-gap height="12"></uv-gap>
			<uv-line color="#eee"></uv-line>
			<OrderInfoItem @tap="sheep.$router.go('/pages/order/testReport')" label="检测报告">
				<view @tap="bigImage(info.jiance_file)" class="ss-flex">
					<view class="fc-dark6 ss-font-28">查看检测报告</view>
					<z-icon name="arrow-right" size="32rpx"></z-icon>
				</view>
			</OrderInfoItem>
			<OrderInfoItem label="复检报告">
				<view @tap="bigImage(info.fujian_file)" class="ss-flex">
					<view class="fc-dark6 ss-font-28">查看复检报告</view>
					<z-icon name="arrow-right" size="32rpx"></z-icon>
				</view>
			</OrderInfoItem>	
			<uv-gap height="12"></uv-gap>
			<RepairPlan isSelect :readOnly="true" :modelValue="state.repairValueList" />
		</view>
		<uv-gap height="50"></uv-gap>
		<z-bottom :zIndex="99">
			<view class="ss-p-x-32 ss-p-y-16 ss-flex gap-24">
				<z-button class="ss-w-100" @tap="state.cancelTipsShow = !state.cancelTipsShow" plan borderColorMain>取消订单</z-button>
				<z-button class="ss-w-100" @tap="changeTipsShow">复核订单 ￥{{ info.all_price }}</z-button>
			</view>
		</z-bottom>
		<z-modaltips @confirm="confirmFuHeOrder" v-model="state.tipsShow" :content="state.tips"></z-modaltips>
		<CancelOrder :info="info" v-model="state.cancelTipsShow" />
	</z-container>
</template>

<script setup>
	import sheep from "@/sheep"
	import OrderMessage from "@/pages/components/OrderMessage"
	import OrderInfoItem from "@/pages/components/OrderInfoItem"
	import RepairPlan from "@/pages/components/RepairPlan"
	import DataTransformer  from "@/sheep/enu/DataTransformer.js"
	import CancelOrder from "@/pages/components/CancelOrder"
	const state = reactive({
		cancelTipsShow:false,
		tips:'确定复核该订单吗，将不可再修改？',
		loading:true
	})
	const info = ref({})
	const form = reactive({
		order_id:'',
		fh_remake:''
	})
	onLoad(({id = ''}) => {
		state.id = id
		form.order_id = id
	})
	onShow(() => {
		getDetail()
	})
	function changeTipsShow(){
		state.tipsShow = !state.tipsShow
	}
	async function confirmFuHeOrder(){
		const { code } = await sheep.$api.user.fuhe_order(form)
			if(code != 1) return
			setTimeout(() => {
				uni.$emit('onReachIndex')
				uni.$emit('onReachOrder')
				sheep.$router.back()
			},1000)
	}
	async function getDetail(){
		const { code,data } = await sheep.$api.user.orderdetail({order_id:state.id})
		if(code != 1) return
		info.value = data
		let fanganlist = data.fanganlist || []
		const result = DataTransformer.transform(fanganlist)
		state.repairValueList = JSON.stringify(result)
		state.loading = false
	}
	function bigImage(url = ''){
		sheep.$helper.openDocument(url)
		// let urls = [sheep.$url.cdn(url)]
		// console.log(urls);
		// uni.previewImage({
		// 	urls
		// })
	}
</script>

<style scoped lang="scss">
	:deep(.uv-border) {
		border-color: #eee !important;
	}
</style>
